package com.aifund.app.controller;

import com.aifund.app.entity.form.regist.PhoneRegisterForm;
import com.aifund.app.entity.form.regist.SendPhoneCodeForm;
import com.aifund.app.entity.vo.PhoneRegisterVo;
import com.aifund.app.service.PhoneCodeService;
import com.aifund.app.service.UserService;
import com.aifund.common.result.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * 用户注册
 */
@RestController
@RequestMapping("/api/register")
@Api(tags = "注册")
public class RegisterController {


    @Autowired
    PhoneCodeService phoneCodeService;
    @Autowired
    UserService userService;

    /**
     * 手机号注册
     * @param form 手机号
     * @return
     */
    @ApiOperation("通过手机号注册")
    @PostMapping("/phoneRegister")
    public ResultBody phoneRegister(@RequestBody @Validated PhoneRegisterForm form){
        PhoneRegisterVo registerVo = userService.registerByPhone(form);
        return ResultBody.success(registerVo);
    }


    /**
     * 发送手机验证码
     * @param form
     * @return
     */
    @PostMapping("/sendPhoneCode")
    @ApiOperation("发送手机验证码")
    public ResultBody sendPhoneCode( @RequestBody @Validated SendPhoneCodeForm form){
        String s = phoneCodeService.sendPhoneCode(form.getPhone());
        return ResultBody.success(s);
    }

}
